import axios from 'axios'
import { Toast } from 'vant'
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    uid:'',
    tpken:'',
    userInfo:{},
    islogin:false,
    cate:[],
    aaa:1
  },
  getters: {
  },
  mutations: {
  // change(state,{key,value}){
    //   state[key]=value
    // },
    change(state,v){
      state[v.key]=v.value
    },
    clear(state){
      state.uid='';
      state.tpken='';
      state.userInfo={};
      state.islogin=false;

    },
    // changeuid(state,v){
    //   state.uid=v
    // },
    // changetpken(state,v){
    //   state.tpken=v
    // },
    // changeuserInfo(state,v){
    //   state.userInfo=v
    // }
  },
  actions: {
    getuserinfo(json,token){
      console.log(token);
      axios.post("https://d33a5037-6c63-4e92-8bb1-30018ab701ea.bspapp.com/http/user/getuserInfo",token).then((res) => {
        console.log(res);
        if(res.code==0){
          json.commit('change',{key:"userInfo",value:res.data.userInfo})
          json.commit('change',{key:"uid",value:res.data.uid})
          json.commit('change',{key:"token",value:res.data.token})
          json.commit('change',{key:"islogin",value:true})
        }else{
          Toast(res.msg)
        }
        
        
        
      });
    },
      getcate({state,commit}){

        axios.post("https://d33a5037-6c63-4e92-8bb1-30018ab701ea.bspapp.com/http/api/get_cate_list").then(res=>{
          console.log(res);
          commit('change',{key:'cate',value:res.data})
        })
      
      },
  },
  modules: {
  }
})
